package com.yichen.music;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.music.Utils.BillboardUtil;
import com.yichen.util.MusicUtil;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class BillboardInfo extends ListActivity implements OnItemClickListener {
	List<String> music_name_data;
	List<Map<String, String>> data_base;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Intent intent = getIntent();
		String billboard_id = intent.getStringExtra("billboard_id");
		BillboardUtil billboard_info = new BillboardUtil();
		// 根据榜单的id获取榜单的前十个歌曲
		data_base = billboard_info.getBillboardInfoById(billboard_id, 0, 100);

		music_name_data = new ArrayList<String>();

		for (Map<String, String> map : data_base) {
			music_name_data.add(map.get("song_name"));
		}

		ArrayAdapter<String> data_adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, music_name_data);

		this.setListAdapter(data_adapter);
		this.getListView().setOnItemClickListener(this);

	}

	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		System.out.println(data_base.get(arg2).get("song_id"));// 获取歌曲的ID
		//
		Intent intent = new Intent();
		intent.setClass(this, MusicPlay.class);
		intent.putExtra("song_id", data_base.get(arg2).get("song_id"));
		intent.putExtra("song_name", music_name_data.get(arg2));
		intent.putExtra("actor_name", data_base.get(arg2).get("actor_name"));

		startActivity(intent);

	}
}
